package repertory.android.ericchen.androidrepertory.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import repertory.android.ericchen.androidrepertory.R;

/**
 * className:
 * author: Ericchen
 * description:
 * date: 2017/3/8 17:31
 * update: 2017/3/8
 * version:
 */
public class MyBottomPoupAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<String> data = new ArrayList<>();
    private boolean hasIcon;
    private ArrayList<Integer> iconData = new ArrayList<>();
    public MyBottomPoupAdapter(Context context,ArrayList<String> data,boolean hasIcon,ArrayList<Integer> iconData){
        this.context = context;
        this.data = data;
        this.hasIcon = hasIcon;
        this.iconData = iconData;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(hasIcon){
            convertView = LayoutInflater.from(context).inflate(R.layout.my_bottom_popup_dialog_item2,null);
        }else{
            convertView = LayoutInflater.from(context).inflate(R.layout.my_bottom_popup_dialog_item,null);
        }
        TextView item =(TextView)convertView.findViewById(R.id.item);
        item.setText(data.get(position));
        ImageView icon = (ImageView)convertView.findViewById(R.id.icon);
        if(icon!=null){
            icon.setImageResource(iconData.get(position));
        }
        return convertView;
    }
}
